<template>
  <div class="header">
    <div class="text">
      <img src="@/assets/logo.jpg" alt="logo" />
      <span>出入登记管理系统</span>
    </div>
    <div class="back">
      <div class="time">{{ nowtime }}</div>
      <n-icon size="40" @click="back" color="#fff" style="cursor: pointer">
        <ArrowHookUpLeft24Filled />
      </n-icon>
    </div>
  </div>
</template>

<script>
import { ArrowHookUpLeft24Filled } from "@vicons/fluent";
import { useRouter } from "vue-router";
import { onBeforeUnmount, onMounted, ref } from "vue";
import { NowTime } from "@/utils/day.js";
export default {
  components: {
    ArrowHookUpLeft24Filled,
  },
  setup() {
    const router = useRouter();
    const back = () => {
      router.push("/");
    };
    const nowtime = ref("");
    //显示当前时间（年月日时分秒）
    const nowTimes = () => {
      nowtime.value = NowTime();
    };

    // const clear = () => {
    //   clearInterval(this.nowTimes);
    //   this.nowTimes = null;
    // };
    onMounted(() => {
      setInterval(nowTimes, 1000);
    });
    onBeforeUnmount(() => {
      clearInterval(nowtime.value);
    });
    return {
      nowtime,
      back,
    };
  },
};
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: 80px;
  background-color: rgba(154, 0, 0, 100);
  position: relative;
  .text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    img {
      height: 60px;
      margin-right: 20px;
    }
    width: 600px;
    height: 80px;
    font-size: 55px;
    color: #fff;
    span {
      font-family: "方正汉真广标-标准";
    }
  }
  .back {
    position: absolute;
    right: 5%;
    top: 50%;
    transform: translate(0, -50%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    .time {
      color: #fff;
      font-size: 20px;
      margin-right: 30px;
    }
  }
}
</style>
